﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace Workbench.Presentation
{
    public class EnumToBoolConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return false;

            return value.Equals(Enum.Parse(value.GetType(), (string)parameter, true));
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value.Equals(false) ? DependencyProperty.UnsetValue : parameter;
        }
    }
}
